#include <string>
#include <iostream>
#include <cerrno>
#include <cstring>
#include <cstdlib>

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h> 


void print(const void* v, size_t s)
{
        const unsigned char* c = (unsigned char*)v;
        for(int i = 0; i < s; i++)
        {
                std::cout << (unsigned int)c[i] << ' ';
        }
        std::cout << std::endl;
}

void compare_addresses(const char* s)
{
        hostent* server = gethostbyname(s);
        if (server == NULL) {
                std::cerr << "No such host" << std::endl;
        }

        sockaddr_in a;
        memset(&a, 0, sizeof(a));
        a.sin_family = AF_INET;
        strcpy((char*)&a.sin_addr, server->h_addr);
        a.sin_port = htons(5678);

        sockaddr_in b;
        memset(&b, 0, sizeof(b));
        b.sin_family = AF_INET;
        inet_pton(AF_INET, s, &b.sin_addr);
        b.sin_port = htons(5678);

        int c = memcmp(&a, &b, sizeof(sockaddr_in));
        std::cout << c << std::endl;
        print(&a, sizeof(sockaddr_in));
        print(&b, sizeof(sockaddr_in));
}

int main(int argc, char *argv[])
{
        compare_addresses("127.0.0.1");
        compare_addresses("192.168.1.71");
        return 0;
}
